package java6703.nio2;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class NIO2NewFile6703 {
    public static void main(String[] args) throws IOException {
        Path path = Paths.get("d:ff.txt");

        if ( !Files.exists(path)) {
            Path parent = path.getParent();
            if (parent != null && ! Files.exists(parent)) {
                if ( ! path.toFile().mkdirs()) {
                    path=Paths.get("d:\\Java6703\\IOException\\"+path.getFileName());
                    path.toFile().mkdirs();
                    System.out.println("不能创建目录:" + parent+"重新指定到当前项目下"+path);

                }
                System.out.println("创建目录:" + path.getParent());
            }
            Files.deleteIfExists(path);
            System.out.println(Files.createFile(path));
        }else {
            System.out.println("文件已存在");
        }
    }
}
